package com.itheima.tliasproject.controller;

import com.itheima.tliasproject.pojo.Emp;
import com.itheima.tliasproject.pojo.Login;
import com.itheima.tliasproject.pojo.Result;
import com.itheima.tliasproject.service.EmpService;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {
    @Autowired
    private EmpService empService;
    @Autowired
    private ResourcePatternResolver resourcePatternResolver;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp) {
        log.info("接收到的数据是：{}", emp);
        Login logininfo = empService.login(emp);
      if (logininfo != null){
          return Result.Success(logininfo);
      }
      return Result.error("用户名或者密码错误");
    }
}
